package com.diligreat.tools;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Properties;

public class MutipleLanguageResources {
	
	/**
	 * --------------------------------------------------------------------------------
	 * 废止使用
	 * @param bPath
	 * @return
	 * @throws IOException
	 */
	public HashMap<String, Properties> readFiles(String bPath) throws IOException
	{
		HashMap<String, Properties> propsMap=new HashMap<String, Properties>();
		
		//String bb="/WEB-INF/classes/languagePackage";
		String bb=this.getClass().getResource("/").getPath()+"/languagePackage";
		
		//System.out.println(this.getClass().getResource("/").getPath());
		
		File file = new File(bb);
		
		File[] filelist = file.listFiles();
		
		for(int i=0;i<filelist.length;i++)
		{
			//System.out.println(filelist[i].getName());
			Properties props = new Properties();  
			InputStream in= new BufferedInputStream(new FileInputStream(bb+"/"+filelist[i].getName()));  
			props.load(in);  
			//String value = props.getProperty("dataSource.username");
			
			
			propsMap.put(filelist[i].getName(), props);
		}
		
		return propsMap;
	}
	
	public HashMap<String, Properties> readFiles() throws IOException
	{
		HashMap<String, Properties> propsMap=new HashMap<String, Properties>();
		
		String bb=this.getClass().getResource("/").getPath()+"/languagePackage";
		
		File file = new File(bb);
		
		File[] filelist = file.listFiles();
		
		for(int i=0;i<filelist.length;i++)
		{
			
			Properties props = new Properties();  
			InputStream in= new BufferedInputStream(new FileInputStream(bb+"/"+filelist[i].getName()));  
			props.load(in);
			
			propsMap.put(filelist[i].getName().split("\\.")[0],props);
		}
		
		return propsMap;
	}
	
}